//
//  TW_MyScene.m
//  Tower
//
//  Created by Jonear on 14-5-10.
//  Copyright (c) 2014年 Jonear. All rights reserved.
//

#import "TW_MyScene.h"
#import "TW_MapFactory.h"

#define MapPointx (is_4Inch ? 105 : 125)
#define MapPointy (is_4Inch ? 196 : 156)
#define HeroPointx (is_4Inch ? 130 : 151)
#define HeroPointy (is_4Inch ? 347 : 306)

@implementation TW_MyScene
{
    TW_HeroSprite *_hero;
}

-(id)initWithSize:(CGSize)size {    
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */
        
        self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
        
        [self initHero];
        [self initMap];

    }
    return self;
}

- (void)initHero
{
    _hero = [[TW_HeroSprite alloc] initWithPosition:[self getPointWithIndexPoint:0 withy:0]];
    [self addChild:_hero];
}

- (void)initMap
{
    JSTileMap *map = [TW_MapFactory getMapWithIndex:0];
    map.position = CGPointMake(MapPointx, MapPointy);
    [self addChild:map];
}

- (CGPoint)getPointWithIndexPoint:(int)x withy:(int)y
{
    return CGPointMake(HeroPointx+x*18, HeroPointy-y*18);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//    /* Called when a touch begins */
}

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
//    NSLog(@"%f", currentTime);
}

//主视图控制英雄移动
- (void)heroMoveTo:(enumHeroMove)move
{
    [_hero heroMoveTo:move];
}

@end
